package com.songpeng.demo;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;

/**
 * @author 86137
 */
public class JsonVerticle extends AbstractVerticle {

  @Override
  public void start(Promise<Void> startPromise) throws Exception {
    vertx.createHttpServer().requestHandler(req -> {
      req.response().putHeader("content-type", "text/plain")
        .end(new JsonObject().put("key", "value").toBuffer());
    }).listen(8888, http -> {
      if (http.succeeded()) {
        startPromise.complete();;
      } else {
        startPromise.fail(http.cause());
      }
    });
  }
}
